<?php 
class bamer_lib{

	function __construct()
	{
		$this->ci =& get_instance();

		$this->ci->load->config('tank_auth', TRUE);

		$this->ci->load->library('session');
		$this->ci->load->database();
		$this->ci->load->model('user');

		$this->ci->load->model('modul/kategori');
		$this->ci->load->model('modul/menu');
		$this->ci->load->model('modul/category');
		$this->ci->load->model('modul/permission');
		

		// Try to autologin
	}


	function user_group(){
		$order = 'id_user_group';
		$by = 'asc';

/*		$this->ci = & get_instance();
		$this->ci->load->model('user');*/
		$rows = $this->ci->user->list_array('user_group', $order, $by);

		$dropdown = array();
		foreach($rows as $row){
			$dropdown[$row->id_user_group] =  $row->permission_name;
		}	
		return $dropdown;
	}

	function user_permmision($id_user_group){
		$where = array('id_user_group' => $id_user_group);

	/*	$this->ci = & get_instance();
		$this->ci->load->model('user');*/
		$rows = $this->ci->user->get('user_group', $where);

		$dropdown = array();
		$value = "";
		foreach($rows as $row){
			$value =  $row->permission_name;
		}	
		return $value;
	}

	

	function url_dir(){
		return "C:/xampp/htdocs/bamer/";
		//return "/home/semut/public_html/";
	}

	

	function check_permission_show($id_user, $menu){
		$permission = $this->ci->permission->check_permission_show($id_user, $menu);
		if($permission == 0){
	
			redirect('modul/user_groups/permission_denied', 'refresh');
		}else{
			return true;
		}
	}
	function check_permission_create($id_user, $menu){
		$permission = $this->ci->permission->check_permission_create($id_user, $menu);
		if($permission == 0){
			redirect('modul/user_groups/permission_denied');
		}else{
			return true;
		}
	}
	function check_permission_update($id_user, $menu){
		$permission = $this->ci->permission->check_permission_update($id_user, $menu);
		if($permission == 0){
			redirect('modul/user_groups/permission_denied');
		}else{
			return true;
		}
	}
	function check_permission_delete($id_user, $menu){
		$permission = $this->ci->permission->check_permission_delete($id_user, $menu);
		if($permission == 0){
			redirect('modul/user_groups/permission_denied');
		}else{
			return true;
		}
	}
	
}
